<template>
	<view class="mainpadding2" style="padding-bottom: 150rpx;">
		<view class="mainpadding_top ffffff radius">
			<view class="titletext xiaohei fonweight">名称</view>
			<input type="text" class="margin_top" v-model="title" placeholder="请输入名称"/>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="titletext xiaohei fonweight">号码</view>
			<input type="text" class="margin_top" v-model="content" placeholder="请输入号码"/>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="titletext xiaohei fonweight">上传logo</view>
			<view class="flexleft flex_wrap">
				<view class="sanshis  flexcenter" @click="uploadImg()">
					<image src="@/static/images/tjtp.png" v-if="images_text==''" class="margin_top"
						style="width: 180rpx;height: 180rpx;" mode=""></image>
					<image :src="images_text" class="margin_top radius" v-else style="width: 180rpx;height: 180rpx;" mode="">
					</image>
				</view>
			</view>
		</view>
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="submit()">提交</view>
		</view>
		<u-popup :show="show" mode="center" round="10" closeable @close="show=false">
			<view class="mainpadding">
				<view class="">
					<view class=" sanshier xiaohei textcenter bold">添加客服</view>
					<image :src="wxkfImg" class="margin_top" style="width: 500rpx;" mode="widthFix"></image>
					<view class="xiaohui ershil margin_top textcenter">添加微信客服缴纳保证金</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")

	export default {
		data() {
			return {
				title: "",
				content: "",
				images: "",
				images_text: "",
				listid: "",
				show:false,
				wxkfImg:""
			}
		},
		onLoad() {
			this.getSystem()
		},
		methods: {
			getSystem() {
				httpRequest.request('/api/index/getConfigInfoItem', 'POST', {
					pidtype: "otherset",
					type: "wechat_code",
				}, false, false, true).then(res => {
					this.wxkfImg = res.data
				})
			},
			submit() {
				if (this.title == "") {
					httpRequest.toast("请输入名称")
					return false
				}
				if (this.content == "") {
					httpRequest.toast("请输入号码")
					return false
				}
				if (this.images=="") {
					httpRequest.toast("请上传logo")
					return false
				}
				let url = "/api/Dmkjcl/addDmkj"
				let data = {
					name: this.title,
					hm: this.content,
					logo: this.images
				}
				httpRequest.request(url, 'GET', data).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==-1){
						this.show = true
						// setTimeout(() => {//未缴纳保证金
						// 	uni.navigateTo({
						// 		url:"/pages_mypage/baozhengj"
						// 	})
						// }, 1000)
					}
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}

				})
			},
			uploadImg(value, upImgs, upImgs_text) { //上传图片
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.images = res.url
					this.images_text = image_item
				}).catch(err => {});
			},
		}
	}
</script>

<style>
	.textarea {
		height: 150rpx;
		width: 100%;
	}
</style>